﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>检验检测现场受理系统</title>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<link href="css/base.css" rel="stylesheet" type="text/css" />
	<script src="scripts/boot.js" type="text/javascript"></script>

	<style type="text/css">
		html, body{
			margin:0;padding:0;border:0;width:100%;height:100%;overflow:hidden;
			color: #555555;
		}

		a {
			color: #555555;
			text-decoration: none;
			outline: none;
		}
		a:hover {
			text-decoration: underline;
		}

		.head {
			width: 100%; margin:0px; padding: 5px 10px; color: #FFFFFF; background-color: #1b6d85;
		}
		.head a {
			color: #FFFFFF;
			text-decoration: none;
			outline: none;
		}

		.action a {
			color: #1b6d85;
		}
	</style>
</head>
<body>
<div style="width: 100%;">
	<h3 class="head"><a href="index.html">检验检测现场受理系统</a></h3>
	<div style="position:absolute; top:5px; right:20px; color: #FFFFFF;">
		当前用户：<span id="userArea"></span><a href="javascript:quit();" style="margin-left: 30px; color: #FFFFFF;">退出</a>
	</div>
</div>
<div style="width:100%;">
	<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
		<table style="width:100%;">
			<tr>
				<td style="white-space:nowrap; padding: 0 7px;">
					<a href="index.html">首页</a> > <span id="spanTitle">委托单[ <span id="spanNo" style="color:#B22222;"></span> ]</span> > <strong>器具管理</strong>
				</td>
			</tr>
		</table>
	</div>
	<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
		<table style="width:100%;">
			<tr>
				<td style="width:100%;">
					<a class="mini-button" iconCls="icon-add" onclick="add()">添加</a>
					<!-- <a class="mini-button" iconCls="icon-edit" onclick="edit()" style="margin-left: 3px;">修改</a> -->
					<!-- <a class="mini-button" iconCls="icon-remove" onclick="remove()" style="margin-left: 3px;">删除</a> -->
					<a class="mini-menubutton" menu="#popupMenu" style="margin-left: 3px;">更多 ...</a>
					<ul id="popupMenu" class="mini-menu" style="display:none;">
						<li iconCls="icon-download" onclick="importExcel()">导入Excel</li>
						<!-- <li class="separator"></li> -->
						<!-- <li iconCls="icon-upload" onclick="exportExcel()">导出Excel</li> -->
						<li class="separator"></li>
						<li iconCls="icon-remove" onclick="remove()">删除选中</li>
						<!-- <li class="separator"></li> -->
					</ul>
				</td>
				<td style="white-space:nowrap;">
					<input id="sampleName" class="mini-textbox" emptyText="输入器具名称" style="width:150px;" onenter="onKeyEnter"/>
					<a class="mini-button" onclick="search()" style="margin-left: 3px;">查询</a>
				</td>
			</tr>
		</table>
	</div>
</div>

<div class="mini-fit" >
	<div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" allowResize="true"
		 idField="id" multiSelect="true" pageSize="20">
		<div property="columns">
			<!-- <div type="indexcolumn"></div> -->
			<div type="checkcolumn" width="30" headerAlign="center" align="center"></div>
			<div field="sampleName" headerAlign="center" align="left" allowSort="true">器具名称</div>
			<div field="specModel" headerAlign="center" align="center" allowSort="true">型号规格</div>
			<div field="dictTestDepartment" headerAlign="center" align="center" allowSort="true" renderer="onDictTestDepartmentRenderer">承检科室</div>
			<div field="dictReportType" headerAlign="center" align="center" allowSort="true" renderer="onDictReportTypeRenderer">检测类型</div>
			<div field="agreedCompletionDate" headerAlign="center" align="center" dateFormat="yyyy-MM-dd" allowSort="true">商定完成日期</div>
			<div field="wantCompleteDate" headerAlign="center" align="center" dateFormat="yyyy-MM-dd" allowSort="true">预计完成日期</div>
			<div field="action" headerAlign="center" align="center" allowSort="false" renderer="onActionRenderer">操作</div>
		</div>
	</div>

</div>

<script type="text/javascript">
	mini.parse();

	var obj = checkSession($);
	if(obj) document.getElementById("userArea").innerHTML = obj.data.webUser.name;

	// 获取委托单ID
	var fkIndentId = getQueryString("id");
	if(fkIndentId) {
		$.ajax({
			url: "/sign/bus/utensil/indent/id/" + fkIndentId,
			type: "post",
			cache: false,
			success: function (text) {
				var o = mini.decode(text);
				var spanTitle = '受理单号：'
						+ o.data.regFormNo
						+ '\n委托单位：' + o.data.nameOfEntrustOrg
						+ '\n证书单位：' + o.data.certificationCompany;
				document.getElementById("spanTitle").title = spanTitle;
				document.getElementById("spanTitle").onclick = function (){
					alert(spanTitle);
				}
				document.getElementById("spanNo").innerHTML = o.data.regFormNo;
			}
		});
	} else {
		alert("页面参数错误，页面将跳转至首页！");
		top.location.href = "index.html";
	}

	var grid = mini.get("datagrid1");
	var params = grid.getLoadParams();
	var pageIndex = 0;
	var pageSize = 20;
	if(params != null) {
		pageIndex = params.pageIndex;
		pageSize = params.pageSize;
	}

	var url = "/sign/bus/utensil/page/";
	grid.on("beforeload", function(e) {
		pageIndex = e.data.pageIndex;
		pageSize = e.data.pageSize;
		e.url = url + pageIndex + "/" + pageSize + "?fkIndentId=" + fkIndentId;
		return true;
	});

	grid.sortBy("createTime", "desc");
	grid.load(url + pageIndex + "/" + pageSize + "?fkIndentId=" + fkIndentId);

	function add() {

		mini.open({
			url: bootPATH + "../device_add.html",
			title: "器具 - 添加", width: 860, height: "100%",
			onload: function () {
				var iframe = this.getIFrameEl();

				var data = { action: "new", id: fkIndentId}; // 传递委托单ID
				iframe.contentWindow.SetData(data);
			},
			ondestroy: function (action) {

				grid.reload();
			}
		});
	}
	function edit(id) {
		if(!id) {
			var row = grid.getSelected();
			if (row) {
				id = row.id;
			} else {
				alert("请选中一条记录");
				return;
			}
		}

		mini.open({
			url: "device_edit.html",
			title: "器具 - 修改", width: 860, height: "100%",
			onload: function () {
				var iframe = this.getIFrameEl();
				var data = { action: "edit", id: id };
				iframe.contentWindow.SetData(data);
			},
			ondestroy: function (action) {
				grid.reload();

			}
		});
	}
	function remove(id) {
		var ids = [];
		if(!id) {
			// 删除选中（未传id）
			var rows = grid.getSelecteds();
			for (var i = 0, l = rows.length; i < l; i++) {
				var r = rows[i];
				ids.push(r.id);
			}
		} else {
			// 删除当前行（传id）
			ids.push(id);
		}

		if(ids.length > 0) {
			// 有删除内容时提醒
			if (!confirm("确定删除选中记录吗？")) {
				return;
			}
		} else {
			// 无删除内容时提醒
			alert("请选中一条记录");
			return;
		}

		// var idArray = ids.join(',');
		grid.loading("操作中，请稍候 ...");
		$.ajax({
			url: "/sign/bus/utensil/removeByIds",
			type: "post",
			data: JSON.stringify(ids),
			dataType:"json",
			contentType: "application/json;charset=UTF-8",
			success: function (text) {
				grid.reload();
			},
			error: function () {
			}
		});
	}
	function search() {
		var sampleName = mini.get("sampleName").getValue();
		grid.load({ sampleName: sampleName });
	}
	function onKeyEnter(e) {
		search();
	}

	function exportExcel() {
		if (!confirm("确定导出全部器具数据吗？")) {
			return;
		}
		var downloadUrl = "/sign/bus/file/download/utensil/" + fkIndentId;
		let iframe = document.createElement("iframe");
		iframe.src = downloadUrl;
		iframe.style.display = "none";
		let fn = function() {
			setTimeout(function() {
				iframe.removeEventListener("load", fn);
				document.body.removeChild(iframe);
			}, 0);
		}
		iframe.addEventListener('load', fn);
		document.body.appendChild(iframe);
	}

	function importExcel() {
		mini.open({
			url: "device_upload.html",
			title: "文件上传", width: 500, height: 260,
			onload: function () {
				var iframe = this.getIFrameEl();
				var data = { action: "new", fkIndentId: fkIndentId};
				iframe.contentWindow.SetData(data);
			},
			ondestroy: function (action) {
				grid.reload();
			}
		});
	}
	/////////////////////////////////////////////////

	function onDictTestDepartmentRenderer(e) {
		if(e.value) {
			return e.value.text;
		} else {
			return "";
		}
	}

	function onDictReportTypeRenderer(e) {
		if(e.value) {
			return e.value.text;
		} else {
			return "";
		}
	}

	function onActionRenderer(e) {
		var s = '<span class="action"><a href="javascript:edit(\''+ e.record.id + '\')">修改</a>'
				+ '<a href="javascript:remove(\''+ e.record.id + '\')" style="margin-left: 10px;">删除</a></span>';
		return s;
	}

	function quit() {
		if (!confirm("确定退出系统吗？")) {
			return;
		}
		$.ajax({
			url: "/sign/login/out",
			type: "post",
			contentType: "application/json;charset=UTF-8",
			dataType: "json",
			cache: false,
			async: false,
			success: function (obj) {
				top.location.href = "login.html";
			},
			error: function (jqXHR, textStatus, errorThrown) {
				console.log(jqXHR.responseText);
				top.location.href = "login.html";
			}
		});
		return returnObj;
	}

	function getQueryString(name) {
		var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
		var r = window.location.search.substr(1).match(reg);
		if (r != null) {
			return unescape(r[2]);
		}
		return null;
	}
</script>

</body>
</html>